var isReady = false;
$(document).ready(function(){
	$("#adminCode").blur(function(){
		var url = "http://localhost:8080/Client/web/admin/check?adminCode=" + $(this).val();
		alert(url);
		checkAdminCode(url);
	});
	$("#submit").click(function(){
		if(isReady == true){
			var url = "http://localhost:8080/Client/web/admin/add";
			var adminCode = $("#adminCode").val();
			var adminName = $("#adminName").val();
			var adminPass = $("#adminPass").val();
			var data = "{\"adminCode\":\""+adminCode+"\",\"adminName\":\""+adminName+"\",\"adminPass\":\""+adminPass+"\"}";
			addAdminReq(data,url);
		}
	});
});
function addAdminReq(data,url){
	$.ajax({
		url:url,
		type:"post",
		dataType:"json",
		data:{
			"data":data
		},
		success:function(data){
			if(data.result == "success"){
				alert("添加成功！");
			}else{
				alert("添加失败！");
			}
			$("#adminCode").val("");
			$("#adminName").val("");
			$("#adminPass").val("");
		},
		error:function(data){
			alert("请求异常！");
			$("#adminCode").val("");
			$("#adminName").val("");
			$("#adminPass").val("");
		}
	});
}
function checkAdminCode(url){
	$.ajax({
		url:url,
		type:"get",
		dataType:"json",
		success:function(data){
			if(data.result == "false"){
				isReady = true;
			}else{
				alert("账号有重复！");
			}
		}
	});
}